#!/usr/bin/python3.9
# -*- coding: utf-8 -*-
# @Time    : 2021/8/30 16:19
# @Author  : YHSimon
from flask import Flask, render_template
import sqlite3

app = Flask(__name__)


@app.route('/')
def index():
    return render_template("index.html")


@app.route("/index")
def home():
    return index()


@app.route("/movie")
def movie():
    dataList = []
    conn = sqlite3.connect("movie250.db")
    cur = conn.cursor()
    sql = "select * from movie250"
    data = cur.execute(sql)
    for item in data:
        dataList.append(item)
    cur.close()
    conn.close()
    return render_template("movie.html", movies=dataList)


@app.route("/score")
def score():
    score = []  # 评分
    num = []  # 每个评分所统计出的电影数量
    conn = sqlite3.connect('movie250.db')
    cur = conn.cursor()
    sql = "select rating,count(rating) from movie250 group by rating"
    data = cur.execute(sql)
    for item in data:
        score.append(str(item[0]))
        num.append(item[1])
    cur.close()
    conn.close()
    return render_template("score.html", score=score, num=num)


@app.route("/word")
def word():
    return render_template("word.html")


@app.route("/team")
def team():
    return render_template("team.html")


if __name__ == '__main__':
    app.run(debug=True)
